// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class videoPlay extends cc.Component {


    // LIFE-CYCLE CALLBACKS:

    @property(cc.VideoPlayer)
    videoplayer: cc.VideoPlayer = null

    flag: boolean = false;

    onLoad () {
        this.videoplayer.node.on('ready-to-play', this.callback, this);
    }

    start () {
        this.videoplayer.node.on('clicked', ()=>{
            this.playVideo();
        }, this)
    }

    callback() {
        this.playVideo();
    }

    playVideo() {
        if (!this.flag) {
            console.log('开始播放');
            this.videoplayer.play();
            this.flag = true;
        } else {
            console.log('停止播放');
            this.videoplayer.pause();
            this.flag = false;
        }
    }
    // update (dt) {}
}
